package com.xz.bigsoubackend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xz.bigsoubackend.common.BaseResponse;
import com.xz.bigsoubackend.common.ErrorCode;
import com.xz.bigsoubackend.common.ResultUtils;
import com.xz.bigsoubackend.exception.ThrowUtils;
import com.xz.bigsoubackend.model.dto.picture.PictureQueryRequest;
import com.xz.bigsoubackend.model.entity.Picture;
import com.xz.bigsoubackend.service.PictureService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author xuzhou
 * @version 1.0
 * @createTime 2024-11-05
 * @description
 */
@RestController
@RequestMapping("picture")
@Slf4j
public class PictureController {

    @Resource
    private PictureService pictureService;

    @PostMapping("/list/page/vo")
    public BaseResponse<Page<Picture>> listPictureByPage(@RequestBody PictureQueryRequest pictureQueryRequest, HttpServletRequest request){
        long current = pictureQueryRequest.getCurrent();
        long pageSize = pictureQueryRequest.getPageSize();
        String searchText = pictureQueryRequest.getSearchText();
        // 限制爬虫
        ThrowUtils.throwIf(pageSize > 20, ErrorCode.PARAMS_ERROR);

        Page<Picture> picturePage = pictureService.searchPicture(searchText, current, pageSize);
        return ResultUtils.success(picturePage);
    }
}
